package refactor.encapsulatecollection;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Person {
    private Set<Course> courses = new HashSet<>();

    public Set<Course> getCourses() {
        return Collections.unmodifiableSet(courses);
    }

    public void addCourse(Course course) {
        courses.add(course);
    }

    public void removeCourse(Course course) {
        courses.remove(course);
    }

    public int getCourseCount() {
        return courses.size();
    }

    public int getAdvancedCourseCount() {
        int count = 0;
        Iterator<Course> courseIterator = courses.iterator();
        while (courseIterator.hasNext()) {
            Course course = courseIterator.next();
            if (course.isAdvanced()) {
                count++;
            }
        }
        return count;
    }
}
